package com.skeleton.server.user.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.skeleton.common.base.dto.ResultDto;
import com.skeleton.db.dto.BlogTagDto;
import com.skeleton.db.dto.UserAttentionDto;
import com.skeleton.db.dto.UserinfoDto;
import com.skeleton.server.blog.service.IBlogTagService;
import com.skeleton.server.user.service.IUserAttentionService;
import com.skeleton.utils.SystemConstants;

@Controller
@RequestMapping("user/attention/")
public class UserAttentionControl {

	protected Logger logger = LogManager.getLogger(this.getClass());

	@Resource
	private IUserAttentionService iUserAttentionService;
	
	@RequestMapping("addBlogUserAttention")
	@ResponseBody
	public Map<String, Object> addBlogUserAttention(HttpServletRequest request, HttpSession session) {
		logger.info("-------user/attention/---addBlogUserAttention-----------------");
		Map<String, Object> map = new HashMap<String, Object>();
		
		String loginname_to = request.getParameter("loginname_to");
		UserinfoDto ud = (UserinfoDto) session.getAttribute(SystemConstants.LOGINUSER_SESSION_NAME);
		
		UserAttentionDto uaDto = new UserAttentionDto();
		uaDto.setLoginnameFrom(ud.getUserLoginname());
		uaDto.setLoginnameTo(loginname_to);
		uaDto.setAttentionType(SystemConstants.USER_ATTENTION_BLOG);

		ResultDto rd = iUserAttentionService.doAddAttention(uaDto);
		if (rd.isSuccess()) {
			map.put("result", SystemConstants.AJAX_SUCCESS);
		} else {
			map.put("result", SystemConstants.AJAX_FAILED_ALERT);
			map.put("msg", rd.getErrorMSG());
		}

		return map;
	}

}
